<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="lib/bootstrap/css/bootstrap.css">
</head>
<body>
<div id="app" class="container" style="margin:200px auto;">
    <div class="row">
        <div class="col-md-4" style="margin:0 auto;">
            <div class="form">
                <div class="form-group">
                    <label>用户名</label>
                    <input id="js-input-userName" type="text" class="form-control">
                </div>
                <div class="form-group">
                    <label>密码</label>
                    <input id="js-input-password" type="password" class="form-control">
                </div>
                <button id="js-btn-login" class="btn btn-info btn-block" style="margin-top:14px;">注册</button>
                <a href="/login" class="btn btn-light btn-block">前往登录</a>
            </div>
        </div>
    </div>
</div>
<script src="lib/jquery/jquery.js"></script>
<script src="js/util.js"></script>
<script>

    $(function () {

        $("#js-btn-login").click(function () {
            // 获取用户名(手机号/邮箱), 密码, 票据
            var userName = $("#js-input-userName").val().trim();
            var password = $("#js-input-password").val();
            if (!userName || !password) {
                alert("请输入账号密码");
                return false;
            }

            $.ajax({
                url: "/api/user/register",
                type: "POST",
                data: { "userName": userName, "password": password},
                dataType: "json",
                success: function (data) {
                    if (data.code > 0) {
                        // 注册成功
                        alert("注册成功, 前往登录")
                        window.location.href = "/login";
                    } else {
                        alert(data.message);
                    }
                }
            });
        });

    });
</script>
</body>
</html>